#include "dialog_login.h"
#include "ui_dialog_login.h"
#include "dialog_register.h"
#include "widget.h"
#include "inifilecontrol.h"
#include <QDebug>
Dialog_Login::Dialog_Login(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog_Login)
{
    ui->setupUi(this);
}

Dialog_Login::~Dialog_Login()
{
    delete ui;
}

void Dialog_Login::on_btn_ok_clicked()
{
    iniFileControl ini;
    QString name = ini.read_ini_file(0);
    QString pwd  = ini.read_ini_file(1);

    qDebug()<<name<<pwd;
    if(name == "" || pwd =="")
        ui->label->setText("没有该用户！");
    else
    {
        QStringList names = name.split(",");
        QStringList pwds  = pwd.split(",");
        int index = names.indexOf(ui->lineEdit_name->text());
        qDebug()<<index;
        if( index>=0)
        {
            QString pwdTemp = pwds.at(names.indexOf(ui->lineEdit_name->text()));
            qDebug()<<pwdTemp<<ui->lineEdit_pwd->text();
            if(pwdTemp.compare(ui->lineEdit_pwd->text())==0)
            {
                accept();
                qDebug()<<"ok";

            }
            else
                ui->label->setText("密码错误！");
        }
    }
}

void Dialog_Login::on_pushButton_clicked()
{
    Dialog_Register *dlg;
    dlg = new Dialog_Register;
    dlg ->exec();

}

void Dialog_Login::on_checkBox_clicked()
{
    if(ui->checkBox->isChecked())
        {
            ui->lineEdit_pwd->setEchoMode(QLineEdit::Normal);   //显示密码
        }
        else
        {
           ui->lineEdit_pwd->setEchoMode(QLineEdit::Password);   //隐藏密码
        }
}
